import request from '@/config/axios'
import axios from 'axios'

/**
 * shp文件解析
 */
export const shpParseApi = (params: any) => {
  return request.upload({ url: '/ability/shapefile/parse', data: params })
}

/**
 * 上传tif 服务
 */
export const tifUploadApi = (params: any) => {
  return request.upload({ url: '/ability/geoserver/tiff/publish', data: params })
}

/**
 * 数学计算
 */

export const mathApi = (params: any) => {
  return request.post({ url: '/ability/math/do', data: params })
}

/**
 * 插值
 */
export const interpolationApi = (params: any) => {
  return request.post({ url: '/ability/interpolation/do', data: params })
}

/**
 * 获取权重
 */
export const getWeight = () => {
  // return new Promise<any>(async (resolve) => {
  //   const { data } = await axios.get('/weight.json')
  //   resolve(data)
  // })
  return request.get({ url: '/ability/weight-data/tree/get', params: { did: 0 } })
}
/**
 * 更新权重
 */

export const updataWeight = (data: any) => {
  return request.put({ url: '/ability/weight-data/update/batch', data })
}

/**
 * 获取单个指标权重矩阵
 */
export const getSingleWeight = (single: string) => {
  return request.get({ url: '/ability/weight/load', params: { id: 1, flag: single.toString() } })
  // return new Promise<any>(async (resolve) => {
  //   const { data } = await axios.get('/method-score.json')
  //   console.log(data)
  //   // 按key分组
  //   function groupAndMerge(ydata) {
  //     const grouped = ydata.reduce((acc, item) => {
  //       if (!acc[item.row]) {
  //         acc[item.row] = { row: item.row, columns: {} }
  //       }
  //       acc[item.row].columns[item.column] = item.value
  //       return acc
  //     }, {})

  //     return Object.values(grouped).map((item: any) => ({
  //       key: item.row,
  //       ...item.columns{}{}
  //     }))
  //   }
  //   const list = groupAndMerge(data)

  //   resolve({
  //     data: list
  //   })
  // })
}

/**
 * 更新单个权证矩阵
 */
export const updataSingleWeight = (single, data: any) => {
  return request.post({
    url: '/ability/weight/save',
    data: { id: 1, flag: single.toString(), data }
  })
}

/**
 * 获取评分
 */
export const getScore = () => {
  return request.get({
    url: '/ability/target-score/list',
    params: {
      did: 0
    }
  })
}

/**
 * 更新评分
 */
export const updateScore = (data) => {
  return request.put({
    url: '/ability/target-score/update/batch',
    data
  })
}

/**
 * 获取转换项
 */
export const getTrans = (single) => {
  return request.get({
    url: '/ability/weight/load',
    params: { id: 1024, flag: single.toString() }
  })
}
/**
 * 更新转换项
 */
export const updateTrans = (single, data) => {
  return request.post({
    url: '/ability/weight/save',
    data: { id: 1024, flag: single.toString(), data }
  })
}

/**
 * 评分转化
 */

export const transScore = (data: any) => {
  return request.post({ url: '/ability/target-score/trans', data })
}
